home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_03_02 / 3n02028a < prev    next >
Text File  |  1991-11-15  |  17KB  |  490 lines

  1. {Font Preview - 1.5 Program Copyright (C) Doug Overmyer 7/26/91}
  2. program FontPreview;
  3. {$S-} {$R PREVIEW.RES}{$R-}
  4. uses WinTypes, WinProcs, WinDos, Strings, WObjects,StdDlgs,Fonts,Buttons;
  5. const
  6.     id_But1    = 201;     {Ownerdraw Button  1  }
  7.   id_But2    = 202;     {      "           2  }
  8.   id_But3    = 203;     {      "           3  }
  9.   id_But4    = 204;     {      "           4  }
  10.   id_But5    = 205;     {      "           5  }
  11.   id_D1Lb1   = 301;     {List box  in Dlg1    }
  12.   id_St1     = 401;     {Static text 1        }
  13.   id_St2     = 402;     {Static text 2        }
  14.   id_St3     = 403;     {Static text 3        }
  15.   id_St4     = 404;     {Static text 4        }
  16.   id_D3Setup = 501;     {Setup button in  Dlg3}
  17.   id_D3EC1     = 506;     {Edit control in  Dlg3}
  18.   id_D3OK    = 521;          {OK button in Dlg3    }
  19.   id_lb2     = 601;     {FBox list box control}
  20.   idm_About  = 801;     {menu id for PV_About menu}
  21.   idm_RunCP  = 802;     {menu id for run control panel}
  22.   idm_RunATM = 803;     {menu id for run ATM  }
  23. type
  24. TPVApplication = object(TApplication)
  25.     procedure InitMainWindow;virtual;
  26. end;
  27.  
  28. PPVDlg1 = ^TPVDlg1;                     {Font Sizes Dialog}
  29. TPVDlg1 = object(TDialog)
  30.     FontSize: Integer;
  31.     procedure WMInitDialog(var Msg:TMessage);virtual wm_First+wm_InitDialog;
  32.   procedure IDD1LB1(var Msg:TMessage);virtual id_First+id_D1Lb1;
  33. end;
  34.  
  35. PPVDlg2 = ^TPVDlg2;                     {String Dialog}
  36. TPVDlg2 = object(TDialog)
  37.     DCType:Char;
  38.     procedure WMInitDialog(var Msg:TMessage);virtual wm_First+wm_InitDialog;
  39. end;
  40.  
  41. type                            {Child win to display sample text}
  42. PFontWindow = ^TFontWindow;
  43. TFontWindow = object(TWindow)
  44.     FontHeight: LongInt;
  45.   constructor Init(AParent: PWindowsObject; ATitle: PChar);
  46.   procedure Paint(PaintDC: HDC; var PaintInfo: TPaintStruct); virtual;
  47. end;
  48.  
  49. type                           {MainWindow of Application}
  50. PPVWindow = ^TPVWindow;
  51. TPVWindow = object(TWindow)
  52.     FWin:PFontWindow;     {child window displaying typeface sample}
  53.   FBox:PListBox;        {List box of available type faces}
  54.   Fonts:PFonts;
  55.   LogPixY:Integer;
  56.   Bn1,Bn2,Bn3,Bn4,Bn5:PODButton;
  57.   Dlg1 : PPVDlg1;                     {Select font size dialog}
  58.   St1,St2,St3,St4:PStatic;
  59.   TextString:Array[0..80] of Char;    {to display in FWin}
  60.   FontSelection:Integer;              {Index into Fonts }
  61.   FontSize:Integer;                   {Current font size }
  62.     constructor Init(AParent:PWindowsObject;ATitle:PChar);
  63.   destructor Done;virtual;
  64.   procedure SetupWindow;virtual;
  65.   procedure Paint(PaintDC:HDC;var PaintInfo:TPaintStruct);virtual;
  66.   procedure    LoadFBox;
  67.   procedure    WMDrawItem(var Msg:TMessage);virtual wm_First + wm_DrawItem;
  68.   procedure WMSize(var Msg:TMessage);virtual wm_First+wm_Size;
  69.   procedure WMSetFocus(var Msg:TMessage);virtual wm_First+wm_SetFocus;
  70.   procedure IDBut1(var Msg:TMessage);virtual id_First+id_But1; {Information}
  71.     procedure IDBut2(var Msg:TMessage);virtual id_First+id_But2; {Size}
  72.   procedure IDBut3(var Msg:TMessage);virtual id_First+id_But3; {String}
  73.   procedure    IDBut4(var Msg:TMessage);virtual id_First+id_But4; {Text Metrics}
  74.   procedure IDBut5(var Msg:TMessage);virtual id_First+id_But5; {Exit}
  75.   procedure    IDLB2(var Msg:TMessage);virtual  id_First+id_lb2;
  76.   procedure EnumerateFonts;virtual;
  77.   procedure    WMSysCommand(var Msg:TMessage);virtual wm_First+wm_SysCommand;
  78.   function GetIC:HDC;virtual;
  79. end;
  80. {*************************** G l o b a l s **************************}
  81. var
  82.     MainWin:PPVWindow;
  83. {*************************** M e t h o d s  *************************}
  84. procedure TPVApplication.InitMainWindow;
  85. begin
  86.     MainWindow := New(PPVWindow,Init(nil,'Font Preview'));
  87.   MainWin := PPVWindow(MainWindow);
  88. end;
  89. {************************** TPVWindow  ******************************}
  90. constructor TPVWindow.Init(AParent:PWindowsObject;ATitle:PChar);
  91. begin
  92.     TWindow.Init(AParent,ATitle);
  93.   Attr.X := 20; Attr.Y := 25; Attr.W := 595; Attr.H := 260;
  94.   Bn1 := New(PODButton,Init(@Self,id_But1,'About',0,0,50,50,False,'PV_Bn1'));
  95.   Bn2 := New(PODButton,Init(@Self,id_But2,'Font Size',50,0,50,50,False,'PV_Bn2'));
  96.   Bn3 := New(PODButton,Init(@Self,id_But3,'String',100,0,100,50,False,'PV_Bn3'));
  97.   Bn4 := New(PODButton,Init(@Self,id_But4,'TM',200,0,50,50,False,'PV_Bn4'));
  98.   Bn5 := New(PODButton,Init(@Self,id_But5,'Exit',250,0,50,50,False,'PV_Bn5'));
  99.    St1 := New(PStatic,Init(@Self,id_St1,'',315,5,240,18,75));
  100.    St2 := New(PStatic,Init(@Self,id_St2,'',315,26,240,18,75));
  101.    St3 := New(PStatic,Init(@Self,id_ST3,'',310,3,250,44,75));
  102.    St4 := New(PStatic,Init(@Self,id_St4,'',5,55,100,18,75));
  103.    St2^.Attr.Style := St2^.Attr.Style or ss_LeftNoWordWrap;
  104.    St3^.Attr.Style := St3^.Attr.Style or ss_BlackFrame;
  105.    St4^.Attr.Style := St4^.Attr.Style or ss_Left;
  106.   FontSelection := 0;
  107.   FontSize := 48;
  108.   StrCopy(TextString,'');
  109.   Fonts := New(PFonts,Init);
  110.   EnumerateFonts;
  111.   FWin := New(PFontWindow,Init(@Self,ATitle));
  112.   With FWin^.Attr do Style := Style or ws_Child or ws_HScroll or ws_VScroll or ws_Border ;
  113.   FBox := New(PListBox,Init(@Self,id_lb2,0,0,0,0));
  114.   With FBox^.Attr do Style := Style and not lbs_Sort;
  115. end;
  116.  
  117. procedure TPVWindow.SetupWindow;
  118. begin
  119.     TWindow.SetupWindow;
  120.     SetClassWord(HWindow,GCW_HIcon,LoadIcon(HInstance,'PV_Icon'));
  121.   AppendMenu(GetSystemMenu(hWindow,false),MF_Separator,0,nil);
  122.   AppendMenu(GetSystemMenu(hWindow,false),0,idm_RunCP,'Run Control Panel');
  123.   AppendMenu(GetSystemMenu(hWindow,false),0,idm_RunATM,'Run ATM');
  124.   AppendMenu(GetSystemMenu(hWindow,false),MF_Separator,0,nil);
  125.   AppendMenu(GetSystemMenu(hWindow,false),0,idm_About,'About...');
  126.     LoadFBox;
  127. end;
  128.  
  129. procedure TPVWindow.Paint(PaintDC:HDC;var PaintInfo:TPaintStruct);
  130. var
  131.     ThePen,OldPen:HPen;
  132.   TheBrush,OldBrush:HBrush;
  133. begin
  134.     TheBrush := GetStockObject(LtGray_Brush);
  135.     ThePen := CreatePen(ps_Solid,1,$00000000);
  136.   OldPen := SelectObject(PaintDC,ThePen);
  137.   OldBrush := SelectObject(PaintDC,TheBrush);
  138.   Rectangle(PaintDC,0,0,1024,50);
  139.   SelectObject(PaintDC,OldBrush);
  140.   SelectObject(PaintDC,OldPen);
  141.   DeleteObject(ThePen);
  142. end;
  143.  
  144. procedure    TPVWindow.WMDrawItem(var Msg:TMessage);
  145. var
  146.     PDIS : ^TDrawItemStruct;
  147. begin
  148.     PDIS := Pointer(Msg.lParam);
  149.    case PDIS^.CtlType of
  150.        odt_Button:
  151.             case PDIS^.CtlID of
  152.           id_But1 :Bn1^.DrawItem(Msg);
  153.                 id_But2 :Bn2^.DrawItem(Msg);
  154.                 id_But3 :Bn3^.DrawItem(Msg);
  155.                 id_But4 :Bn4^.DrawItem(Msg);
  156.                 id_But5 :Bn5^.DrawItem(Msg);
  157.         end;
  158.    end;
  159. end;
  160.  
  161. destructor TPVWindow.Done;
  162. begin
  163.     Dispose(BN1,Done);Dispose(Bn2,Done);Dispose(Bn3,Done);
  164.   Dispose(Bn4,Done);Dispose(Bn5,Done);Dispose(St1,done);
  165.   Dispose(St2,Done);Dispose(St3,Done);Dispose(St4,Done);
  166.     TWindow.Done;
  167. end;
  168.  
  169. procedure TPVWindow.WMSize(var Msg:TMessage);
  170. begin
  171.     SetWindowPos(FBox^.HWindow,0,-1,75,(Msg.LParamLo div 3)+1,
  172.        ((Msg.LParamHi-70)  ),swp_NoZOrder);
  173.     SetWindowPos(FWin^.HWindow,0,(Msg.LParamLo  div 3)-1,49,
  174.        (Msg.LParamLo * 2 div 3)+1,(Msg.LParamHi-48),swp_NoZOrder);
  175. end;
  176.  
  177. procedure TPVWindow.WMSetFocus(var Msg:TMessage);
  178. begin
  179.     SetFocus(FBox^.HWindow);
  180. end;
  181.  
  182. procedure TPVWindow.IDBut1(var Msg:TMessage);
  183. begin
  184.     Application^.ExecDialog(New(PDialog,Init(@Self,'PV_About')));
  185. end;
  186.  
  187. procedure TPVWindow.IDBut2(var Msg:TMessage);
  188. begin
  189.     Dlg1 := new(PPVDlg1,Init(@Self,'PV_Dlg1'));
  190.   Application^.ExecDialog(Dlg1);
  191.   if (Dlg1^.FontSize) <> 0 then InvalidateRect(Fwin^.HWindow,nil,True);
  192. end;
  193.  
  194. procedure TPVWindow.IDBut3(var Msg:TMessage);
  195. begin
  196.    If Application^.ExecDialog(New(PInputdialog,Init(@Self,'Font String',
  197.        'Enter text:',TextString,SizeOf(TextString)))) <> 1 then StrCopy(TextString,'');
  198.   InvalidateRect(FWin^.HWindow,nil,True);
  199. end;
  200.  
  201. procedure TPVWindow.IDBut4(var Msg:TMessage);
  202. var
  203.     Dlg : PPVDlg2;
  204. begin
  205.     Dlg :=New(PPVDlg2,Init(@Self,'PV_Dlg2'));
  206.   Dlg^.DCType := 'S';
  207.     Application^.ExecDialog(Dlg);
  208.     Dlg :=New(PPVDlg2,Init(@Self,'PV_Dlg2'));
  209.   Dlg^.DCType := 'P';
  210.     Application^.ExecDialog(Dlg);
  211. end;
  212.  
  213. procedure TPVWindow.IDBut5(var Msg:TMessage);
  214. begin
  215.     CloseWindow;
  216. end;
  217.  
  218. procedure TPVWindow.LoadFBox;
  219. var
  220.     Indx : Integer;
  221.   Font : PFontItem;
  222.   Buf